

var mongoose = require('mongoose');

// console.log(mongoose);

// var dbhost = "0.0.0.0";//自动匹配获取localhost地址
var dbhost = "localhost"

var dbport = 27017;

var dbname = "wuhan2004";

var dbuser = "";

var dbpass = "";

var db_url = `mongodb://${dbhost}:${dbport}/${dbname}`;

mongoose.connect(`mongodb://${dbhost}:${dbport}/${dbname}`,{
    useNewUrlParser:true,  //解决两个warnning
    useUnifiedTopology:true
},function(err){
    if(err){
        console.log('数据库连接失败');
        console.log(err);
    }
    else{
        console.log('数据库连接成功');
    }
})


const connection = mongoose.connection;
// console.log(connection);


connection.on("connected",()=>{
    console.log('数据库已连接');
})


connection.on("err",()=>{
    console.log('数据库连接异常');
})


connection.on("disconnected",()=>{
    console.log('数据库连接已断开');
})


module.exports = connection;